<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

<p:outputPanel id="czPanel" layout="block" style="margin: 50px 0;">
    <div class="table-top-panel">
        <p:graphicImage value="../../resources/img/icons/citizen.png"/>
        <p:outputLabel value="Cetatenie" styleClass="table-label"/>
    </div>
    <h:form id="cz-formId">
        <p:dataTable id="czData" var="c" value="#{additionalDataBean.citizens}" editable="true"
                     emptyMessage="Nu sunt inregistrari pentru dosarul curent"
                     rowIndexVar="rowIndex" styleClass="data-table-style data-table-panel">

            <p:column headerText="Cetatenie">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{c.citizenship.name}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:selectOneMenu value="#{c.citizenship}" required="true" style="width: 200px;"
                                         converter="#{objectMappingConverter}">
                            <f:selectItem itemLabel="Selectati cetatenia"/>
                            <f:selectItems var="cs" value="#{additionalDataBean.citizenShips}"
                                           itemLabel="#{cs.name}"
                                           itemValue="#{cs}"/>
                        </p:selectOneMenu>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Actiuni" width="15%">
                <p:rowEditor id="cz-row-editor"/>
                <p:commandLink value="Delete" actionListener="#{additionalDataBean.deleteCitizen(c)}"
                               update="czData"/>
            </p:column>

        </p:dataTable>

        <p:commandLink value="Adauga cetatenie" actionListener="#{additionalDataBean.addNewCitizen('cz-row-editor')}"/>
    </h:form>
</p:outputPanel>

<p:outputPanel id="docPanel" layout="block" style="margin: 50px 0;">
    <div class="table-top-panel">
        <p:graphicImage value="../../resources/img/icons/document.png"/>
        <p:outputLabel value="Acte de identitate" styleClass="table-label"/>
    </div>
    <h:form id="doc-formId">
        <p:dataTable id="docData" var="d" value="#{additionalDataBean.documents}" editable="true"
                     emptyMessage="Nu sunt inregistrari pentru dosarul curent"
                     rowIndexVar="rowIndex" styleClass="data-table-style data-table-panel">

            <p:column headerText="Document">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{d.documentType.name}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:selectOneMenu value="#{d.documentType}" required="true" style="width: 200px;"
                                         converter="#{objectMappingConverter}">
                            <f:selectItem itemLabel="Selectati tipul"/>
                            <f:selectItems var="dt" value="#{additionalDataBean.documentTypes}"
                                           itemLabel="#{dt.name}" itemValue="#{dt}"/>
                        </p:selectOneMenu>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Numarul">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{d.number}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{d.number}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Data emiterii">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{d.issueDate}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{d.issueDate}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Locul nasterii">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{d.birthPlace}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{d.birthPlace}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Data nasterii">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{d.birthDate}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{d.birthDate}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Domiciliul">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{d.residenceVisa}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{d.residenceVisa}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Autoritatea emitenta">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{d.residenceVisa}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{d.residenceVisa}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Actiuni" width="15%">
                <p:rowEditor id="doc-row-editor"/>
                <p:commandLink value="Delete" actionListener="#{additionalDataBean.deleteDocument(d)}"
                               update="docData"/>
            </p:column>

        </p:dataTable>

        <p:commandLink value="Adauga act de identitate" actionListener="#{additionalDataBean.addNewDocument('doc-row-editor')}"/>
    </h:form>
</p:outputPanel>

<p:outputPanel id="fmPanel" layout="block" style="margin: 50px 0;">
    <div class="table-top-panel">
        <p:graphicImage value="../../resources/img/icons/family.png"/>
        <p:outputLabel value="Membri ai familiei" styleClass="table-label"/>
    </div>
    <h:form id="fm-formId">
        <p:dataTable id="fmData" var="fm" value="#{additionalDataBean.familyMembers}" editable="true"
                     emptyMessage="Nu sunt inregistrari pentru dosarul curent"
                     rowIndexVar="rowIndex" styleClass="data-table-style data-table-panel">

            <p:column headerText="Grad de rudenie">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{fm.familyRelation.name}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:selectOneMenu value="#{fm.familyRelation}" required="true" style="width: 200px;"
                                         converter="#{objectMappingConverter}">
                            <f:selectItem itemLabel="Selectati gradul"/>
                            <f:selectItems var="fr" value="#{additionalDataBean.familyRelations}"
                                           itemLabel="#{fr.name}" itemValue="#{fr}"/>
                        </p:selectOneMenu>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="NPP">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{fm.name}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:inputText value="#{fm.name}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Data nasterii">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{fm.birthDate}"/>
                    </f:facet>

                    <f:facet name="input">
                        <p:calendar value="#{fm.birthDate}" required="true"/>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Actiuni" width="15%">
                <p:rowEditor id="fm-row-editor"/>
                <p:commandLink value="Delete" actionListener="#{additionalDataBean.deleteFamilyMember(fm)}"
                               update="fmData"/>
            </p:column>

        </p:dataTable>

        <p:commandLink value="Adauga membru de familie" actionListener="#{additionalDataBean.addNewFamilyMember('fm-row-editor')}"/>
    </h:form>
</p:outputPanel>


</ui:composition>